var myCirclePlayer;
var currItemNumber;
var sermonList = [
	"../AUDIO/2008/VAN%20DYKE/10-19-08%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2008/VAN%20DYKE/10-19-08%20PM%20VAN%20DYKE.mp3",
	"../AUDIO/2008/VAN%20DYKE/10-26-08%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2008/VAN%20DYKE/11-02-08%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2008/VAN%20DYKE/11-09-08%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2008/VAN%20DYKE/11-09-08%20PM%20VAN%20DYKE.mp3",
	"../AUDIO/2008/VAN%20DYKE/11-16-08%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2008/VAN%20DYKE/11-23-08%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2008/VAN%20DYKE/11-30-08%20AM%20VAN%20DYKE%20JOHN%201.mp3",
	"../AUDIO/2008/VAN%20DYKE/12-07-08%20AM%20VAN%20DYKE%20JOHN%201%20GRACE%20AND%20TRUTH.mp3",
	"../AUDIO/2008/VAN%20DYKE/12-14-08%20AM%20VAN%20DYKE%20JOHN%201.mp3",
	"../AUDIO/2008/VAN%20DYKE/12-14-08%20PM%20VAN%20DYKE%20JOHN%201.mp3",
	"../AUDIO/2009/VAN%20DYKE/01-11-09%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2008/VAN%20DYKE/12-28-08%20AM%20VAN%20DYKE%20RECIEVING%20HIM.mp3",
	"../AUDIO/2008/VAN%20DYKE/12-21-08%20AM%20VAN%20DYKE%20HIS%20BIRTH.mp3",
	"../AUDIO/2009/VAN%20DYKE/01-18-09%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2009/VAN%20DYKE/01-25-09%20AM%20VAN%20DYKE%20John%202-12-22%20CLEANSING%20THE%20TEMPLE.mp3",
	"../AUDIO/2009/VAN%20DYKE/02-01-09%20AM%20VAN%20DYKE%20John%202-23%20Divine%20Must.mp3",
	"../AUDIO/2009/VAN%20DYKE/02-08-09%20AM%20VAN%20DYKE%20John%203-10-17%20more%20than%20a%20teacher.mp3",
	"../AUDIO/2009/VAN%20DYKE/02-15-09%20AM%20VAN%20DYKE%20John%203-15-18.mp3",
	"../AUDIO/2009/VAN%20DYKE/02-22-09%20AM%20VAN%20DYKE%20%20The%20Kind%20of%20God%20WE%20Have.mp3",
	"../AUDIO/2009/VAN%20DYKE/03-01-09%20AM%20VAN%20DYKE%20LOVE'S%20REDEMPTIVE%20SACRIFICE.mp3",
	"../AUDIO/2009/VAN%20DYKE/03-08-09%20AM%20VAN%20DYKE%20Gods%20gift..mp3",
	"../AUDIO/2009/VAN%20DYKE/03-15-09%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2009/VAN%20DYKE/04-19-09%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2009/VAN%20DYKE/04-26-09%20AM%20VAN%20DYKE%20John%203%20The%20Sinner-savior-servant.mp3",
	"../AUDIO/2009/VAN%20DYKE/05-03-09%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2009/VAN%20DYKE/05-17-09%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2009/VAN%20DYKE/05-24-09%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2009/VAN%20DYKE/05-31-09%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/06-06-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/06-13-10%20AM%20VANDYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/06-20-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/06-27-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/07-04-10%20AM%20VANDYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/07-10-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/07-18-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/07-25-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/08-01-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/08-29-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/09-05-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/09-12-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/09-19-10%20%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/10-10-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/10-24-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/10-31-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/11-07-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/11-14-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/11-21-10%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/11-28-2010%20%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2010/VAN%20DYKE/12-5-2010%20%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/01-16-2011%20%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/01-23-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/01-30-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/02-13-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/02-20-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/02-27-2011%20%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/03-06-2011%20%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/03-13-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/03-20-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/04-03-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/04-17-2011%20%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/05-01-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/05-15-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/05-22-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/05-29-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/06-05-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/06-19-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/06-19-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/06-26-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/07-03-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/07-10-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/07-17-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/07-24-2011%20%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/07-31-2011%20%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/08-07-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/08-14-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/08-21-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/08-28-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/09-04-2011%20AM%20VAN%20DYKE.mp3",
	"../AUDIO/2011/VAN%20DYKE/09-18-2011%20AM%20VAN%20DYKE.mp3"
];

function selectItem(item) {
    if (0 <= currItemNumber && currItemNumber < sermonList.length) {
    	var currItem = document.getElementById("player-item-" + currItemNumber.toString());
        removeClass(currItem, 'bold');
        removeClass(currItem, 'colorPrimary-5');
        addClass(currItem, 'colorSecondary-a-2');
    }
    addClass(item, 'bold');
    addClass(item, 'colorPrimary-5');
    removeClass(item, 'colorSecondary-a-2');
    currItemNumber = parseInt(item.id.substr(item.id.lastIndexOf("-") + 1));
    myCirclePlayer.setMedia({
    	mp3: sermonList[currItemNumber]
    });
}

function playItem(item) {
    selectItem(item);
	myCirclePlayer.play();
}

function playNextItem() {
    var nextItemNumber = currItemNumber + 1;
    if (nextItemNumber < sermonList.length) {
        playItem(document.getElementById("player-item-" + nextItemNumber.toString()));
    }
}

$(document).ready(function(){
	myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
	{
	}, {
		supplied: "mp3",
		cssSelectorAncestor: "#cp_container_1",
		swfPath: "../Content/Javascript/jplayer/Jplayer.swf",
		wmode: "window",
		keyEnabled: true
	});

    $("#jquery_jplayer_1").bind($.jPlayer.event.ended, function (event) {
        playNextItem();
    });
    
    for(var i = 0; i < sermonList.length; ++i){
		addClass(document.getElementById("player-item-" + i.toString()), 'colorSecondary-a-2');
	}

    selectItem(document.getElementById("player-item-0"));
});
